package com.erp.entity.sale;

import com.erp.entity.goods.MultipleUnit;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class SaleRejectedDetail {
    private Integer id;

    private String linkRejectNumber;//关联销货退货单编号
    private String linkSaleOrderNumber;//关联销货订单编号
    private String linkLogisticNumber;//关联物流单编号
    private String linkQuoteNumber;//关联报价单号
    private String linkSaleNumber;//关联销货单编号


    private Integer goodsId;

    private Integer goodsNum;
    private Integer basicUnitId;//基本单位ID
    private Integer multipleUnitId;//多单位ID

    private Integer sellwareHouseId;

    private Integer basicNum;

    private BigDecimal salePrice;

    private Integer isGift;
    private BigDecimal salePriceTaxDis;//折后含税单价(折后单价+税率*商品单价)

    private BigDecimal taxRate;

    private BigDecimal goodsSalePriceTax;

    private BigDecimal goodsTaxPrice;

    private BigDecimal goodsDiscountRate;

    private BigDecimal goodsDiscountNum;

    private BigDecimal goodsSalePriceDis;

    private BigDecimal goodsTotalPriceDis;

    private BigDecimal priceAndTax;

    private String sourceOrderNum;

    private Integer isExamined;

    private BigDecimal actualCost;//实际成本

    private BigDecimal eGrossProfit;

    private BigDecimal eGrossProfitPc;

    private BigDecimal recentCost;//最近一次采购价

    private Integer companyId;
    private Integer returnableNum;//可退数量
    private Integer detailUnshippedNum;//明细未入库数量

    private String goodsRemarks;
    //----------冗余字段-------
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date receiptDate;//生成销货单时，根据商品查询销货订单明细时表格中要展示的字段
    private String goodsName;//商品名称
    private String goodsImage;//商品图片
    private String goodsAttribute;//商品属性
    private String goodsBrand;//商品品牌
    private String goodsCode;//商品编号

    private String basicUnitName;//基本单位名称

    private String multipleUnitName;//多单位名称
    private String sellwareHouseName;//出库仓库名称
    private List<MultipleUnit> multipleUnitList;

    public SaleRejectedDetail(BigDecimal salePrice){//用来生产销货订单的构造方法，初始化数据
        //设置商品数量初始参数
        setBasicNum(1);
        setGoodsNum(1);
        this.salePrice = salePrice;
        //设置税率相关初始参数
        setTaxRate(BigDecimal.ZERO);//税率
        setGoodsTaxPrice(BigDecimal.ZERO);//税额
        setGoodsSalePriceTax(salePrice);//含税单价
        setSalePriceTaxDis(salePrice);//折后含税单价
        //设置价税合计
        setPriceAndTax(getSalePriceTaxDis().multiply(BigDecimal.valueOf(getGoodsNum())));//价税合计
        //设置折扣率相关初始参数
        setGoodsDiscountRate(BigDecimal.ZERO);//折扣率
        setGoodsDiscountNum(BigDecimal.ZERO);//折扣额
        setGoodsSalePriceDis(salePrice);//设置商品折后单价
        //设置商品的折后金额
        setGoodsTotalPriceDis(getGoodsSalePriceDis().multiply(BigDecimal.valueOf(getBasicNum())));
    }
    public SaleRejectedDetail(BigDecimal salePrice,BigDecimal taxRate,
                           BigDecimal discountRate,Integer goodsNum,
                           Integer basicNum){
        setGoodsNum(goodsNum);
        setBasicNum(basicNum);
        setSalePrice(salePrice);


        //设置税率相关信息
        setTaxRate(taxRate);
        setGoodsTaxPrice(BigDecimal.valueOf(getBasicNum()).multiply(salePrice).multiply(getTaxRate().multiply(BigDecimal.valueOf(0.01))));//计算税额
        setGoodsSalePriceTax(salePrice.add(salePrice.multiply(taxRate.multiply(BigDecimal.valueOf(0.01)))));//设置含税单价

        //设置折扣相关信息
        setGoodsDiscountRate(discountRate);//设置商品折扣率
        setGoodsDiscountNum(BigDecimal.valueOf(basicNum)
                .multiply(discountRate.multiply(BigDecimal.valueOf(0.01)))
                .multiply(salePrice));//设置商品折扣额
        setGoodsSalePriceDis(discountRate.multiply(salePrice).multiply(BigDecimal. valueOf(0.01)).add(salePrice)); //设置商品折后单价
        setGoodsTotalPriceDis(getGoodsSalePriceDis().multiply(BigDecimal.valueOf(getBasicNum())));//设置商品折后金额
        setSalePriceTaxDis(getGoodsSalePriceDis().add(salePrice.multiply(getTaxRate().multiply(BigDecimal.valueOf(0.01)))));//设置商品折后含税单价
        //设置商品价税合计
        setPriceAndTax(getSalePriceTaxDis().multiply(BigDecimal.valueOf(basicNum)));
    }
    public void setBasicInfo(BigDecimal salePrice){//用来生产销货订单的构造方法，初始化数据
        //设置商品数量初始参数
        setBasicNum(1);
        setGoodsNum(1);
        this.salePrice = salePrice;
        //设置税率相关初始参数
        setTaxRate(BigDecimal.ZERO);//税率
        setGoodsTaxPrice(BigDecimal.ZERO);//税额
        setGoodsSalePriceTax(salePrice);//含税单价
        setSalePriceTaxDis(salePrice);//折后含税单价
        //设置价税合计
        setPriceAndTax(getSalePriceTaxDis().multiply(BigDecimal.valueOf(getGoodsNum())));//价税合计
        //设置折扣率相关初始参数
        setGoodsDiscountRate(BigDecimal.ZERO);//折扣率
        setGoodsDiscountNum(BigDecimal.ZERO);//折扣额
        setGoodsSalePriceDis(salePrice);//设置商品折后单价
        //设置商品的折后金额
        setGoodsTotalPriceDis(getGoodsSalePriceDis().multiply(BigDecimal.valueOf(getBasicNum())));
    }
    public void setBasicInfo(BigDecimal salePrice,Integer goodsNum,Integer basicNum){//用来生产销货订单的构造方法，初始化数据
        //设置商品数量初始参数
        setBasicNum(basicNum);
        setGoodsNum(goodsNum);
        this.salePrice = salePrice;
        //设置税率相关初始参数
        setTaxRate(BigDecimal.ZERO);//税率
        setGoodsTaxPrice(BigDecimal.ZERO);//税额
        setGoodsSalePriceTax(salePrice);//含税单价
        setSalePriceTaxDis(salePrice);//折后含税单价
        //设置价税合计
        setPriceAndTax(getSalePriceTaxDis().multiply(BigDecimal.valueOf(getGoodsNum())));//价税合计
        //设置折扣率相关初始参数
        setGoodsDiscountRate(BigDecimal.ZERO);//折扣率
        setGoodsDiscountNum(BigDecimal.ZERO);//折扣额
        setGoodsSalePriceDis(salePrice);//设置商品折后单价
        //设置商品的折后金额
        setGoodsTotalPriceDis(getGoodsSalePriceDis().multiply(BigDecimal.valueOf(getBasicNum())));
    }
}